<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Hash;

class LoginController extends Controller
{
    public function login()
    {
        return view('users.login');
    }

    public function dologin(Request $request)
    {
        $username = $request -> username;
        $user = DB::table('user') -> where('userName',$username) -> first();
        //dd($user);
        if (empty($user)) {
            return view('users.register') -> with('info','用户不存在,请注册');
        }

        if (Hash::check($request -> password, $user -> password)) {
            session(['id' => $user -> id]);

            return redirect('/user') -> with('info','登陆成功');
        } else {
            return back();
        }
    }
}
